package com.example;

import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.databinding.ObservableArrayMap;
import android.databinding.ObservableInt;

public class ObservableUser extends BaseObservable {

    private String firstName;
    private String lastName;

    // 以下两个成员发生变化，不同手动通知
    public final ObservableInt age = new ObservableInt();
    public final ObservableArrayMap<String, Object> grades = new ObservableArrayMap<>();

    private String portrait;

    public ObservableUser() {
        age.set(10);
        grades.put("math", "95");
        grades.put("english", "10");

    }

    public ObservableUser(String firstName, String lastName, int age, String portrait) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.age.set(age);
        this.portrait = portrait;
    }

    @Bindable
    public String getFirstName() {
        return this.firstName;
    }
    @Bindable
    public String getLastName() {
        return this.lastName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
        //　通知数据发生变化
        notifyPropertyChanged(BR.firstName);
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
        notifyPropertyChanged(BR.lastName);
    }

    @Bindable
    public String getPortrait() {
        return portrait;
    }

    public void setPortrait(String portrait) {
        this.portrait = portrait;
        notifyPropertyChanged(BR.portrait);
    }
}